package com.atguigu.gmall.cart.config;

import com.atguigu.gmall.common.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

@Data
@Slf4j
@ConfigurationProperties(prefix = "jwt.auth")
@Configuration
public class JwtProperties {
    private String publicKeyFileName;
    private Long expire;//: 10080
    private String cookieName;//: "GMALL-TOKEN"
    private String userKey;// userKey
    private String token;//: token

    private PublicKey publicKey;

    @PostConstruct
    public void init(){
        try {
            publicKey = RsaUtils.getPublicKey(publicKeyFileName);
        } catch (Exception e) {
            log.error("构建公钥失败："+ ExceptionUtils.getStackTrace(e));
        }
    }
}
